package io.renren.modules.web.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.entity.ProductTypeEntity;
import io.renren.modules.sys.service.ProductTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author zyj
 * @email 740916741@qq.com
 * @date 2019-03-21 10:46:35
 */
@RestController
@RequestMapping("web/producttype")
public class WebProductTypeController {
    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 列表
     */
    @RequestMapping("/listPage")
    public R listPage(@RequestParam Map<String, Object> params){
        PageUtils page = productTypeService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        List<ProductTypeEntity> list = productTypeService.queryList(params);
        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
			ProductTypeEntity productType = productTypeService.selectById(id);
        return R.ok().put("productType", productType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ProductTypeEntity productType){
        productType.setCreateTime(new Date());
			productTypeService.insert(productType);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ProductTypeEntity productType){
			productTypeService.updateById(productType);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
			productTypeService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

}
